package com.edu.edumanager.exception;


import com.edu.edumanager.vo.EduResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: springboot1
 * @description:
 * @author: Jaime
 * @create: 2021-08-01 14:41
 **/
@ControllerAdvice
@ResponseBody
public class GlobalException {
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public EduResult validateException(MethodArgumentNotValidException e) {
        return  EduResult.error("数据填写有误，校验未通过"+e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public EduResult globalException(Exception e) {
        return  EduResult.error("全局出问题了"+e.getMessage());
    }

    @ExceptionHandler({EduException.class})
    public EduResult customException(Exception e) {
        return  EduResult.error("业务未成功"+e.getMessage());
    }

}
